<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title>mu-inheritance</title>
	<script type="text/javascript" src="js/mu.js" charset="utf-8"></script>

</head>

<body>
<script type="text/javascript" charset="utf-8">
    function Animal(){
        this.Name;
        this.eat=function(){
                console.log(this.Name+" is Eating ...");
        }
        //Constructor of Animal
        this.Animal=function(name){
                this.Name=name;
        }
    }

    var something = $(Animal).New("Something");
    something.eat();

    function Dog(){
        //inheritance
        $(this).Extends(Animal);

        this.woof = function(){console.log(this.Name+" is Woofing ...");}
        this.Dog=function(name){
                //Call Parent constructor
                this.Animal(name);
        }
    }

    var Wolf = $(Dog).New("Wolfy");
    Wolf.eat();
    Wolf.woof();

    console.log("---------------------------------------------------");
    console.log(something.constructor.name);
    console.log($(something).Is(Animal)+" "+$(something).Is(Dog));
    console.log(Wolf.constructor.name);
    console.log($(Wolf).Is(Animal)+" "+$(Wolf).Is(Dog));

    function Human(){
        var that = this;

        var name = "John Doe";
        //Constructor
        that.Human = function(pname){
            if(pname!=undefined){name = pname;}
        }

        that.getName = function(){
                return name;
        }

        that.setName = function(value){
                name = value;
        }
    }

    function Man(){
        var that = this;
        $(that).Extends(Human);

        var nickName;

        that.Man = function(name,pnickname){
                that.Human(name);
                nickName = pnickname;

                //increment static variable
                Man.Count+=1;
        }

        that.getNickName = function(){
                return nickName;
        }

        that.setNickName = function(value){
                nickName = value;
        }

        that.hello = function(){
                console.log("Hello, I am " + that.getName() + " aka "+ that.getNickName());
        }
    }
    //Static
    Man.Count = 0;

    var someone = $(Human).New();
    console.log("Some one : " + someone.getName());
    //someone.setName("SOMEONE");

    var bob = $(Man).New();
    console.log("Bob : " + bob.getName());
    bob.setName("BOB");

    console.log("Some one : " + someone.getName());
    console.log("Bob : " + bob.getName());

    someone.setName("SOMEONE");
    console.log("Some one : " + someone.getName());
    console.log("Bob : " + bob.getName());

    var sam = $(Man).New("Sam");
    var bill = $(Man).New("Bill","Billou");

    bob.hello();
    sam.hello();
    bill.hello();

    sam.setNickName("Samy"); sam.setName("SAM THE PIRATE");
    bob.setNickName("Boby");

    bob.hello();
    sam.hello();
    bill.hello();

    console.log(Man.Count);

    console.log(bob.constructor.name);
    console.log(someone.constructor.name);

    console.log($(bob).Is(Man));
    console.log($(bob).Is(Human));
    console.log($(someone).Is(Man));
    console.log($(someone).Is(Human));
    
    

</script>
</body>
</html>
